﻿using APP.HELPER.Utils.CustomizeToolbox;
using APP.HELPER.Utils.Language;
using Common;
using Common.Base;
using Common.Class;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using Extra.ERP;
using Security.ERP;
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;

namespace Security.Security
{
    public class xucUserAdd : xucBaseAdd
    {
        private ComboBoxEdit cboManagement;
        private GridLookUpEdit cbxGroup;
        private CheckEdit chxUse;
        private GridColumn colEmployeeCode;
        private GridColumn colFirstName;
        private GridColumn colGroup_ID;
        private GridColumn colGroup_Name;
        private GridColumn colLastName;
        private IContainer components = null;
        private GridLookUpEdit glkBranch;
        private GridLookUpEdit glkDepartment;
        private GridLookUpEdit glkEmployee;
        private GridLookUpEdit glkGroup;
        private GridColumn gridColumn10;
        private GridColumn gridColumn5;
        private GridColumn gridColumn6;
        private GridColumn gridColumn7;
        private GridColumn gridColumn8;
        private GridColumn gridColumn9;
        private GridView gridLookUpEdit1View;
        private GridView gridView1;
        private GridView gridView2;
        private GridView gridView4;
        private GridView gridView5;
        private LabelControl labelControl2;
        private LabelControl lbBranch;
        private LabelControl lbDepartment;
        private LabelControl lbGroup;
        private LabelControl lblConfirm;
        private LabelControl lblDescription;
        private LabelControl lblEmail;
        private LabelControl lblPassword;
        private LabelControl lblRoles;
        private LabelControl lbManagement;
        private TextEdit txtDescription;
        private TextEdit txtEmployeeName;
        private TextEdit txtMail;
        private TextEdit txtPassword;
        private TextEdit txtRepassword;

        public event SuccessEventHander Success;

        public xucUserAdd()
        {
            this.InitializeComponent();
            this.InitMultiLanguages();
            this.Init();
            this.InitData();
        }

        private void cboManagement_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.cboManagementSelect();
        }

        private void cboManagementSelect()
        {
            if (this.cboManagement.SelectedIndex == 0)
            {
                this.glkGroup.EditValue = null;
                this.glkDepartment.EditValue = null;
                this.glkBranch.EditValue = null;
                this.lbGroup.Visible = false;
                this.glkGroup.Visible = false;
                this.lbDepartment.Visible = false;
                this.glkDepartment.Visible = false;
                this.lbBranch.Visible = false;
                this.glkBranch.Visible = false;
            }
            else if (this.cboManagement.SelectedIndex == 1)
            {
                this.glkGroup.EditValue = null;
                this.glkDepartment.EditValue = null;
                this.glkBranch.EditValue = null;
                this.lbGroup.Visible = false;
                this.glkGroup.Visible = false;
                this.lbDepartment.Visible = false;
                this.glkDepartment.Visible = false;
                this.lbBranch.Visible = true;
                this.glkBranch.Visible = true;
            }
            else if (this.cboManagement.SelectedIndex == 2)
            {
                this.glkGroup.EditValue = null;
                this.glkDepartment.EditValue = null;
                this.glkBranch.EditValue = null;
                this.lbGroup.Visible = false;
                this.glkGroup.Visible = false;
                this.lbDepartment.Visible = true;
                this.glkDepartment.Visible = true;
                this.lbBranch.Visible = true;
                this.glkBranch.Visible = true;
            }
            else
            {
                this.glkGroup.EditValue = null;
                this.glkDepartment.EditValue = null;
                this.glkBranch.EditValue = null;
                this.lbGroup.Visible = true;
                this.glkGroup.Visible = true;
                this.lbDepartment.Visible = true;
                this.glkDepartment.Visible = true;
                this.lbBranch.Visible = true;
                this.glkBranch.Visible = true;
            }
        }

        private void cbxGroup_EditValueChanged(object sender, EventArgs e)
        {
            if (this.gridLookUpEdit1View.GetFocusedRowCellValue(this.colGroup_ID).ToString() == "employee")
            {
                this.lbManagement.Visible = false;
                this.cboManagement.Visible = false;
                this.glkGroup.EditValue = null;
                this.glkDepartment.EditValue = null;
                this.glkBranch.EditValue = null;
                this.lbGroup.Visible = false;
                this.glkGroup.Visible = false;
                this.lbDepartment.Visible = false;
                this.glkDepartment.Visible = false;
                this.lbBranch.Visible = false;
                this.glkBranch.Visible = false;
            }
            else
            {
                this.lbManagement.Visible = true;
                this.cboManagement.Visible = true;
                this.cboManagementSelect();
            }
        }

        protected override bool Check()
        {
            if (this.cbxGroup.EditValue == null)
            {
                XtraMessageBox.Show("Lỗi:\n\tNh\x00f3m người d\x00f9ng chưa chọn", "Th\x00f4ng b\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }
            if (string.Compare(this.txtPassword.Text, this.txtRepassword.Text) != 0)
            {
                XtraMessageBox.Show("Lỗi:\n\tX\x00e1c nhận mật khẩu chưa đ\x00fang!", "Th\x00f4ng b\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.txtRepassword.Focus();
                return false;
            }
            return true;
        }

        public void Clear()
        {
            base.txtID.Text = "";
            base.txtNAME.Text = "";
            this.txtDescription.Text = "";
            this.txtPassword.Text = "";
            this.txtRepassword.Text = "";
            this.txtMail.Text = "";
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void glk_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            xfmGroupAdd.AddedEventHander hander = null;
            if (e.Button.Kind == ButtonPredefines.Plus)
            {
                GridLookUpEdit edit = sender as GridLookUpEdit;
                string name = edit.Name;
                if ((name != null) && (name == "cbxGroup"))
                {
                    xfmGroupAdd add = new xfmGroupAdd(Actions.Add);
                    if (hander == null)
                    {
                        hander = (s, i) => this.LoadGridLookupEdit();
                    }
                    add.Added += hander;
                    add.ShowDialog();
                }
            }
        }

        private void glkBranch_EditValueChanged(object sender, EventArgs e)
        {
            if (this.glkBranch.EditValue != null)
            {
                new SYS_USER().AddDepartmentGridLookupEdit(this.glkDepartment, this.glkBranch.EditValue.ToString());
            }
        }

        private void glkDepartment_EditValueChanged(object sender, EventArgs e)
        {
            if (this.glkDepartment.EditValue != null)
            {
                new SYS_USER().AddGroupGridLookupEdit(this.glkGroup, this.glkDepartment.EditValue.ToString());
            }
            if (this.glkGroup.Text == "")
            {
                this.glkGroup.EditValue = null;
            }
        }

        private void glkEmployee_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            if (e.Button.Kind == ButtonPredefines.Delete)
            {
                this.glkEmployee.EditValue = null;
            }
        }

        private void glkEmployee_EditValueChanged(object sender, EventArgs e)
        {
            if ((this.glkEmployee.EditValue == null) || (this.glkEmployee.EditValue.ToString() == ""))
            {
                this.txtEmployeeName.EditValue = null;
            }
            else
            {
                DataTable employee = new SYS_USER().GetEmployee(this.glkEmployee.EditValue.ToString());
                this.txtEmployeeName.Text = employee.Rows[0]["FirstName"].ToString() + " " + employee.Rows[0]["LastName"].ToString();
            }
        }

        protected void Init()
        {
            this.LoadGridLookupEdit();
            this.cbxGroup.EditValue = "admin";
        }

        private void InitData()
        {
            SYS_USER sys_user = new SYS_USER();
            sys_user.AddBranchGridLookupEdit(this.glkBranch);
            sys_user.AddEmployeeGridLookupEdit(this.glkEmployee);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucUserAdd));
            SerializableAppearanceObject appearance = new SerializableAppearanceObject();
            this.lblRoles = new LabelControl();
            this.lblPassword = new LabelControl();
            this.txtPassword = new TextEdit();
            this.lblConfirm = new LabelControl();
            this.txtRepassword = new TextEdit();
            this.txtDescription = new TextEdit();
            this.lblDescription = new LabelControl();
            this.chxUse = new CheckEdit();
            this.cbxGroup = new GridLookUpEdit();
            this.gridLookUpEdit1View = new GridView();
            this.colGroup_ID = new GridColumn();
            this.colGroup_Name = new GridColumn();
            this.lblEmail = new LabelControl();
            this.txtMail = new TextEdit();
            this.cboManagement = new ComboBoxEdit();
            this.glkBranch = new GridLookUpEdit();
            this.gridView1 = new GridView();
            this.gridColumn5 = new GridColumn();
            this.gridColumn6 = new GridColumn();
            this.glkDepartment = new GridLookUpEdit();
            this.gridView4 = new GridView();
            this.gridColumn7 = new GridColumn();
            this.gridColumn8 = new GridColumn();
            this.glkGroup = new GridLookUpEdit();
            this.gridView5 = new GridView();
            this.gridColumn9 = new GridColumn();
            this.gridColumn10 = new GridColumn();
            this.lbManagement = new LabelControl();
            this.lbBranch = new LabelControl();
            this.lbDepartment = new LabelControl();
            this.lbGroup = new LabelControl();
            this.labelControl2 = new LabelControl();
            this.txtEmployeeName = new TextEdit();
            this.glkEmployee = new GridLookUpEdit();
            this.gridView2 = new GridView();
            this.colEmployeeCode = new GridColumn();
            this.colFirstName = new GridColumn();
            this.colLastName = new GridColumn();
            base.txtNAME.Properties.BeginInit();
            base.imageCollection2.BeginInit();
            base.gcInfo.BeginInit();
            base.gcInfo.SuspendLayout();
            ((ISupportInitialize)base.Err).BeginInit();
            base.txtID.Properties.BeginInit();
            this.txtPassword.Properties.BeginInit();
            this.txtRepassword.Properties.BeginInit();
            this.txtDescription.Properties.BeginInit();
            this.chxUse.Properties.BeginInit();
            this.cbxGroup.Properties.BeginInit();
            this.gridLookUpEdit1View.BeginInit();
            this.txtMail.Properties.BeginInit();
            this.cboManagement.Properties.BeginInit();
            this.glkBranch.Properties.BeginInit();
            this.gridView1.BeginInit();
            this.glkDepartment.Properties.BeginInit();
            this.gridView4.BeginInit();
            this.glkGroup.Properties.BeginInit();
            this.gridView5.BeginInit();
            this.txtEmployeeName.Properties.BeginInit();
            this.glkEmployee.Properties.BeginInit();
            this.gridView2.BeginInit();
            base.SuspendLayout();
            base.txtNAME.Location = new Point(0x42, 0x19);
            base.txtNAME.Size = new Size(0x116, 20);
            base.txtNAME.TabIndex = 0;
            base.txtNAME.EditValueChanged += new EventHandler(this.txtNAME_EditValueChanged);
            base.imageCollection2.ImageStream = (ImageCollectionStreamer)manager.GetObject("imageCollection2.ImageStream");
            base.gcInfo.Controls.Add(this.glkEmployee);
            base.gcInfo.Controls.Add(this.txtEmployeeName);
            base.gcInfo.Controls.Add(this.labelControl2);
            base.gcInfo.Controls.Add(this.lbGroup);
            base.gcInfo.Controls.Add(this.lbDepartment);
            base.gcInfo.Controls.Add(this.lbBranch);
            base.gcInfo.Controls.Add(this.lbManagement);
            base.gcInfo.Controls.Add(this.glkGroup);
            base.gcInfo.Controls.Add(this.glkDepartment);
            base.gcInfo.Controls.Add(this.glkBranch);
            base.gcInfo.Controls.Add(this.cboManagement);
            base.gcInfo.Controls.Add(this.lblEmail);
            base.gcInfo.Controls.Add(this.txtMail);
            base.gcInfo.Controls.Add(this.cbxGroup);
            base.gcInfo.Controls.Add(this.chxUse);
            base.gcInfo.Controls.Add(this.lblDescription);
            base.gcInfo.Controls.Add(this.txtDescription);
            base.gcInfo.Controls.Add(this.lblConfirm);
            base.gcInfo.Controls.Add(this.txtRepassword);
            base.gcInfo.Controls.Add(this.lblRoles);
            base.gcInfo.Controls.Add(this.lblPassword);
            base.gcInfo.Controls.Add(this.txtPassword);
            base.gcInfo.Dock = DockStyle.Top;
            base.gcInfo.Location = new Point(0, 0);
            base.gcInfo.Size = new Size(0x162, 370);
            base.gcInfo.Controls.SetChildIndex(this.txtPassword, 0);
            base.gcInfo.Controls.SetChildIndex(this.lblPassword, 0);
            base.gcInfo.Controls.SetChildIndex(this.lblRoles, 0);
            base.gcInfo.Controls.SetChildIndex(base.lblName, 0);
            base.gcInfo.Controls.SetChildIndex(base.txtNAME, 0);
            base.gcInfo.Controls.SetChildIndex(base.lblId, 0);
            base.gcInfo.Controls.SetChildIndex(base.txtID, 0);
            base.gcInfo.Controls.SetChildIndex(this.txtRepassword, 0);
            base.gcInfo.Controls.SetChildIndex(this.lblConfirm, 0);
            base.gcInfo.Controls.SetChildIndex(this.txtDescription, 0);
            base.gcInfo.Controls.SetChildIndex(this.lblDescription, 0);
            base.gcInfo.Controls.SetChildIndex(this.chxUse, 0);
            base.gcInfo.Controls.SetChildIndex(this.cbxGroup, 0);
            base.gcInfo.Controls.SetChildIndex(this.txtMail, 0);
            base.gcInfo.Controls.SetChildIndex(this.lblEmail, 0);
            base.gcInfo.Controls.SetChildIndex(this.cboManagement, 0);
            base.gcInfo.Controls.SetChildIndex(this.glkBranch, 0);
            base.gcInfo.Controls.SetChildIndex(this.glkDepartment, 0);
            base.gcInfo.Controls.SetChildIndex(this.glkGroup, 0);
            base.gcInfo.Controls.SetChildIndex(this.lbManagement, 0);
            base.gcInfo.Controls.SetChildIndex(this.lbBranch, 0);
            base.gcInfo.Controls.SetChildIndex(this.lbDepartment, 0);
            base.gcInfo.Controls.SetChildIndex(this.lbGroup, 0);
            base.gcInfo.Controls.SetChildIndex(this.labelControl2, 0);
            base.gcInfo.Controls.SetChildIndex(this.txtEmployeeName, 0);
            base.gcInfo.Controls.SetChildIndex(this.glkEmployee, 0);
            base.txtID.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            base.txtID.Location = new Point(0xb7, 0x153);
            base.txtID.Properties.Appearance.ForeColor = Color.DeepSkyBlue;
            base.txtID.Properties.Appearance.Options.UseForeColor = true;
            base.txtID.Size = new Size(0x72, 20);
            base.txtID.Visible = false;
            base.btnSave.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            base.btnSave.Location = new Point(10, 0x17e);
            base.btnSave.Size = new Size(0x5e, 0x1b);
            base.btnSave.TabIndex = 0;
            base.lblName.Location = new Point(7, 0x1c);
            base.lblName.Size = new Size(0x12, 13);
            base.lblName.Text = "T\x00ean";
            base.lblId.Appearance.ForeColor = Color.Black;
            base.lblId.Appearance.Options.UseForeColor = true;
            base.lblId.Location = new Point(7, 8);
            base.lblId.Visible = false;
            base.btnSaveNew.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            base.btnSaveNew.Location = new Point(0x9a, 0x17e);
            base.btnSaveNew.Size = new Size(90, 0x1b);
            base.btnSaveNew.TabIndex = 1;
            base.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            base.btnCancel.Location = new Point(250, 0x17f);
            base.btnCancel.TabIndex = 2;
            this.lblRoles.Location = new Point(7, 0x68);
            this.lblRoles.Name = "lblRoles";
            this.lblRoles.Size = new Size(0x1f, 13);
            this.lblRoles.TabIndex = 5;
            this.lblRoles.Text = "Vai tr\x00f2";
            this.lblPassword.Location = new Point(7, 0x36);
            this.lblPassword.Name = "lblPassword";
            this.lblPassword.Size = new Size(0x2c, 13);
            this.lblPassword.TabIndex = 7;
            this.lblPassword.Text = "Mật khẩu";
            this.txtPassword.Location = new Point(0x42, 0x33);
            this.txtPassword.Name = "txtPassword";
            this.txtPassword.Properties.PasswordChar = '*';
            this.txtPassword.Size = new Size(0x116, 20);
            this.txtPassword.TabIndex = 1;
            this.txtPassword.Click += new EventHandler(this.txtPassword_Click);
            this.lblConfirm.Location = new Point(7, 80);
            this.lblConfirm.Name = "lblConfirm";
            this.lblConfirm.Size = new Size(0x2c, 13);
            this.lblConfirm.TabIndex = 9;
            this.lblConfirm.Text = "X\x00e1c nhận";
            this.txtRepassword.Location = new Point(0x42, 0x4d);
            this.txtRepassword.Name = "txtRepassword";
            this.txtRepassword.Properties.PasswordChar = '*';
            this.txtRepassword.Size = new Size(0x116, 20);
            this.txtRepassword.TabIndex = 2;
            this.txtRepassword.Click += new EventHandler(this.txtRepassword_Click);
            this.txtDescription.Location = new Point(0x42, 180);
            this.txtDescription.Name = "txtDescription";
            this.txtDescription.Size = new Size(0x116, 20);
            this.txtDescription.TabIndex = 7;
            this.lblDescription.Location = new Point(7, 0xb8);
            this.lblDescription.Name = "lblDescription";
            this.lblDescription.Size = new Size(40, 13);
            this.lblDescription.TabIndex = 12;
            this.lblDescription.Text = "Diễn giải";
            this.chxUse.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.chxUse.EditValue = true;
            this.chxUse.Location = new Point(0x43, 340);
            this.chxUse.Name = "chxUse";
            this.chxUse.Properties.Caption = "C\x00f2n quản l\x00fd";
            this.chxUse.Size = new Size(0x62, 0x13);
            this.chxUse.TabIndex = 13;
            this.cbxGroup.Location = new Point(0x42, 0x66);
            this.cbxGroup.Name = "cbxGroup";
            this.cbxGroup.Properties.ActionButtonIndex = 1;
            this.cbxGroup.Properties.AutoComplete = false;
            this.cbxGroup.Properties.BestFitMode = BestFitMode.BestFitResizePopup;
            this.cbxGroup.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Plus, "Th\x00eam", -1, true, true, false, ImageLocation.MiddleCenter, null, new KeyShortcut(Keys.None), appearance, "", "Add", null, true), new EditorButton(ButtonPredefines.Combo) });
            this.cbxGroup.Properties.NullText = "";
            this.cbxGroup.Properties.PopupFilterMode = PopupFilterMode.Contains;
            this.cbxGroup.Properties.View = this.gridLookUpEdit1View;
            this.cbxGroup.Size = new Size(0x116, 20);
            this.cbxGroup.TabIndex = 3;
            this.cbxGroup.ButtonClick += new ButtonPressedEventHandler(this.glk_ButtonClick);
            this.cbxGroup.EditValueChanged += new EventHandler(this.cbxGroup_EditValueChanged);
            this.gridLookUpEdit1View.Columns.AddRange(new GridColumn[] { this.colGroup_ID, this.colGroup_Name });
            this.gridLookUpEdit1View.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            this.gridLookUpEdit1View.Name = "gridLookUpEdit1View";
            this.gridLookUpEdit1View.OptionsSelection.EnableAppearanceFocusedCell = false;
            this.gridLookUpEdit1View.OptionsView.ShowGroupPanel = false;
            this.colGroup_ID.Caption = "M\x00e3";
            this.colGroup_ID.FieldName = "Group_ID";
            this.colGroup_ID.Name = "colGroup_ID";
            this.colGroup_ID.OptionsColumn.FixedWidth = true;
            this.colGroup_ID.Visible = true;
            this.colGroup_ID.VisibleIndex = 0;
            this.colGroup_ID.Width = 100;
            this.colGroup_Name.Caption = "Vai Tr\x00f2";
            this.colGroup_Name.FieldName = "Group_Name";
            this.colGroup_Name.Name = "colGroup_Name";
            this.colGroup_Name.OptionsColumn.FixedWidth = true;
            this.colGroup_Name.Visible = true;
            this.colGroup_Name.VisibleIndex = 1;
            this.colGroup_Name.Width = 200;
            this.lblEmail.Location = new Point(7, 0x9e);
            this.lblEmail.Name = "lblEmail";
            this.lblEmail.Size = new Size(0x18, 13);
            this.lblEmail.TabIndex = 0x11;
            this.lblEmail.Text = "Email";
            this.txtMail.Location = new Point(0x42, 0x9a);
            this.txtMail.Name = "txtMail";
            this.txtMail.Size = new Size(0x116, 20);
            this.txtMail.TabIndex = 6;
            this.cboManagement.EditValue = "Tất Cả";
            this.cboManagement.Location = new Point(0x41, 0xde);
            this.cboManagement.Name = "cboManagement";
            this.cboManagement.Properties.Appearance.Font = new Font("Tahoma", 8.25f, FontStyle.Bold);
            this.cboManagement.Properties.Appearance.Options.UseFont = true;
            this.cboManagement.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.cboManagement.Properties.Items.AddRange(new object[] { "Tất Cả", "Theo Chi Nh\x00e1nh", "Theo Ph\x00f2ng Ban", "Theo Tổ Nh\x00f3m" });
            this.cboManagement.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
            this.cboManagement.Size = new Size(0x117, 20);
            this.cboManagement.TabIndex = 8;
            this.cboManagement.SelectedIndexChanged += new EventHandler(this.cboManagement_SelectedIndexChanged);
            this.glkBranch.Location = new Point(0x41, 0xf8);
            this.glkBranch.Name = "glkBranch";
            this.glkBranch.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.glkBranch.Properties.NullText = "[Chọn chi nh\x00e1nh]";
            this.glkBranch.Properties.View = this.gridView1;
            this.glkBranch.Size = new Size(0x117, 20);
            this.glkBranch.TabIndex = 9;
            this.glkBranch.Visible = false;
            this.glkBranch.EditValueChanged += new EventHandler(this.glkBranch_EditValueChanged);
            this.gridView1.Columns.AddRange(new GridColumn[] { this.gridColumn5, this.gridColumn6 });
            this.gridView1.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            this.gridView1.Name = "gridView1";
            this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
            this.gridView1.OptionsView.ShowGroupPanel = false;
            this.gridColumn5.Caption = "M\x00e3 chi nh\x00e1nh";
            this.gridColumn5.FieldName = "BranchCode";
            this.gridColumn5.Name = "gridColumn5";
            this.gridColumn5.Visible = true;
            this.gridColumn5.VisibleIndex = 0;
            this.gridColumn6.Caption = "T\x00ean chi nh\x00e1nh";
            this.gridColumn6.FieldName = "BranchName";
            this.gridColumn6.Name = "gridColumn6";
            this.gridColumn6.Visible = true;
            this.gridColumn6.VisibleIndex = 1;
            this.glkDepartment.Location = new Point(0x41, 0x114);
            this.glkDepartment.Name = "glkDepartment";
            this.glkDepartment.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.glkDepartment.Properties.NullText = "[Chọn ph\x00f2ng ban thuộc chi nh\x00e1nh]";
            this.glkDepartment.Properties.View = this.gridView4;
            this.glkDepartment.Size = new Size(0x117, 20);
            this.glkDepartment.TabIndex = 10;
            this.glkDepartment.Visible = false;
            this.glkDepartment.EditValueChanged += new EventHandler(this.glkDepartment_EditValueChanged);
            this.gridView4.Columns.AddRange(new GridColumn[] { this.gridColumn7, this.gridColumn8 });
            this.gridView4.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            this.gridView4.Name = "gridView4";
            this.gridView4.OptionsSelection.EnableAppearanceFocusedCell = false;
            this.gridView4.OptionsView.ShowGroupPanel = false;
            this.gridColumn7.Caption = "M\x00e3 ph\x00f2ng ban";
            this.gridColumn7.FieldName = "DepartmentCode";
            this.gridColumn7.Name = "gridColumn7";
            this.gridColumn7.Visible = true;
            this.gridColumn7.VisibleIndex = 0;
            this.gridColumn8.Caption = "T\x00ean ph\x00f2ng ban";
            this.gridColumn8.FieldName = "DepartmentName";
            this.gridColumn8.Name = "gridColumn8";
            this.gridColumn8.Visible = true;
            this.gridColumn8.VisibleIndex = 1;
            this.glkGroup.Location = new Point(0x41, 0x130);
            this.glkGroup.Name = "glkGroup";
            this.glkGroup.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.glkGroup.Properties.NullText = "[Chọn tổ nh\x00f3m thuộc ph\x00f2ng ban]";
            this.glkGroup.Properties.View = this.gridView5;
            this.glkGroup.Size = new Size(0x117, 20);
            this.glkGroup.TabIndex = 11;
            this.glkGroup.Visible = false;
            this.gridView5.Columns.AddRange(new GridColumn[] { this.gridColumn9, this.gridColumn10 });
            this.gridView5.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            this.gridView5.Name = "gridView5";
            this.gridView5.OptionsSelection.EnableAppearanceFocusedCell = false;
            this.gridView5.OptionsView.ShowGroupPanel = false;
            this.gridColumn9.Caption = "M\x00e3 tổ nh\x00f3m";
            this.gridColumn9.FieldName = "GroupCode";
            this.gridColumn9.Name = "gridColumn9";
            this.gridColumn9.Visible = true;
            this.gridColumn9.VisibleIndex = 0;
            this.gridColumn10.Caption = "T\x00ean tổ nh\x00f3m";
            this.gridColumn10.FieldName = "GroupName";
            this.gridColumn10.Name = "gridColumn10";
            this.gridColumn10.Visible = true;
            this.gridColumn10.VisibleIndex = 1;
            this.lbManagement.Location = new Point(8, 0xe0);
            this.lbManagement.Name = "lbManagement";
            this.lbManagement.Size = new Size(0x25, 13);
            this.lbManagement.TabIndex = 0x16;
            this.lbManagement.Text = "Quản l\x00fd";
            this.lbBranch.Location = new Point(7, 0xfc);
            this.lbBranch.Name = "lbBranch";
            this.lbBranch.Size = new Size(0x30, 13);
            this.lbBranch.TabIndex = 0x17;
            this.lbBranch.Text = "Chi nh\x00e1nh";
            this.lbBranch.Visible = false;
            this.lbDepartment.Location = new Point(7, 0x117);
            this.lbDepartment.Name = "lbDepartment";
            this.lbDepartment.Size = new Size(0x33, 13);
            this.lbDepartment.TabIndex = 0x18;
            this.lbDepartment.Text = "Ph\x00f2ng ban";
            this.lbDepartment.Visible = false;
            this.lbGroup.Location = new Point(9, 0x134);
            this.lbGroup.Name = "lbGroup";
            this.lbGroup.Size = new Size(0x29, 13);
            this.lbGroup.TabIndex = 0x19;
            this.lbGroup.Text = "Tổ nh\x00f3m";
            this.lbGroup.Visible = false;
            this.labelControl2.Location = new Point(6, 130);
            this.labelControl2.Name = "labelControl2";
            this.labelControl2.Size = new Size(0x30, 13);
            this.labelControl2.TabIndex = 0x1a;
            this.labelControl2.Text = "Nh\x00e2n vi\x00ean";
            this.txtEmployeeName.Enabled = false;
            this.txtEmployeeName.Location = new Point(0xb7, 0x80);
            this.txtEmployeeName.Name = "txtEmployeeName";
            this.txtEmployeeName.Properties.NullText = "[Họ t\x00ean nh\x00e2n vi\x00ean]";
            this.txtEmployeeName.Size = new Size(0xa1, 20);
            this.txtEmployeeName.TabIndex = 5;
            this.glkEmployee.Location = new Point(0x42, 0x80);
            this.glkEmployee.Name = "glkEmployee";
            this.glkEmployee.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo), new EditorButton(ButtonPredefines.Delete) });
            this.glkEmployee.Properties.NullText = "[Chọn nh\x00e2n vi\x00ean]";
            this.glkEmployee.Properties.View = this.gridView2;
            this.glkEmployee.Size = new Size(0x6f, 20);
            this.glkEmployee.TabIndex = 4;
            this.glkEmployee.ButtonClick += new ButtonPressedEventHandler(this.glkEmployee_ButtonClick);
            this.glkEmployee.EditValueChanged += new EventHandler(this.glkEmployee_EditValueChanged);
            this.gridView2.Columns.AddRange(new GridColumn[] { this.colEmployeeCode, this.colFirstName, this.colLastName });
            this.gridView2.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            this.gridView2.Name = "gridView2";
            this.gridView2.OptionsSelection.EnableAppearanceFocusedCell = false;
            this.gridView2.OptionsView.ShowAutoFilterRow = true;
            this.gridView2.OptionsView.ShowGroupPanel = false;
            this.colEmployeeCode.Caption = "M\x00e3 nh\x00e2n vi\x00ean";
            this.colEmployeeCode.FieldName = "EmployeeCode";
            this.colEmployeeCode.Name = "colEmployeeCode";
            this.colEmployeeCode.Visible = true;
            this.colEmployeeCode.VisibleIndex = 0;
            this.colFirstName.Caption = "Họ l\x00f3t";
            this.colFirstName.FieldName = "FirstName";
            this.colFirstName.Name = "colFirstName";
            this.colFirstName.Visible = true;
            this.colFirstName.VisibleIndex = 1;
            this.colLastName.Caption = "T\x00ean";
            this.colLastName.FieldName = "LastName";
            this.colLastName.Name = "colLastName";
            this.colLastName.Visible = true;
            this.colLastName.VisibleIndex = 2;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Name = "xucUserAdd";
            base.Size = new Size(0x162, 0x1a3);
            base.txtNAME.Properties.EndInit();
            base.imageCollection2.EndInit();
            base.gcInfo.EndInit();
            base.gcInfo.ResumeLayout(false);
            base.gcInfo.PerformLayout();
            ((ISupportInitialize)base.Err).EndInit();
            base.txtID.Properties.EndInit();
            this.txtPassword.Properties.EndInit();
            this.txtRepassword.Properties.EndInit();
            this.txtDescription.Properties.EndInit();
            this.chxUse.Properties.EndInit();
            this.cbxGroup.Properties.EndInit();
            this.gridLookUpEdit1View.EndInit();
            this.txtMail.Properties.EndInit();
            this.cboManagement.Properties.EndInit();
            this.glkBranch.Properties.EndInit();
            this.gridView1.EndInit();
            this.glkDepartment.Properties.EndInit();
            this.gridView4.EndInit();
            this.glkGroup.Properties.EndInit();
            this.gridView5.EndInit();
            this.txtEmployeeName.Properties.EndInit();
            this.glkEmployee.Properties.EndInit();
            this.gridView2.EndInit();
            base.ResumeLayout(false);
        }

        private void InitMultiLanguages()
        {
            this.lblPassword.Text = MultiLanguages.GetString("tbl_UserAdd", "Password", this.lblPassword.Text);
            this.lblConfirm.Text = MultiLanguages.GetString("tbl_UserAdd", "Confirm", this.lblConfirm.Text);
            this.lblRoles.Text = MultiLanguages.GetString("tbl_UserAdd", "Group_ID", this.lblRoles.Text);
            this.lblDescription.Text = MultiLanguages.GetString("tbl_UserAdd", "Description", this.lblDescription.Text);
            this.chxUse.Text = MultiLanguages.GetString("tbl_UserAdd", "Active", this.chxUse.Text);
        }

        private void LoadGridLookupEdit()
        {
            new SYS_GROUP().AddGridLookupEdit(this.cbxGroup);
        }

        public void RaiseSuccessEventHander(SYS_USER Item)
        {
            if (this.Success != null)
            {
                this.Success(this, Item);
            }
        }

        public void SetData(SYS_USER item, bool MyAccount)
        {
            SYS_LOG.Insert("Quản L\x00fd Người D\x00f9ng", "Xem", item.UserID);
            base.txtID.Text = item.UserID;
            if (base.m_Status == Actions.Update)
            {
                base.txtID.Properties.ReadOnly = true;
                base.txtNAME.Properties.ReadOnly = true;
            }
            if (MyAccount)
            {
                this.cbxGroup.Properties.ReadOnly = true;
                this.chxUse.Properties.ReadOnly = true;
            }
            base.txtNAME.Text = item.UserName;
            this.txtDescription.Text = item.Description;
            this.txtPassword.Text = "<Ẩn>";
            this.txtRepassword.Text = "<Ẩn>";
            this.cbxGroup.EditValue = item.Group_ID;
            if (this.cbxGroup.EditValue.ToString() == "employee")
            {
                this.lbManagement.Visible = false;
                this.cboManagement.Visible = false;
            }
            this.txtMail.Text = item.Email;
            this.chxUse.Checked = item.Active;
            this.cboManagement.SelectedIndex = item.Management;
            this.glkBranch.EditValue = item.BranchCode;
            SYS_USER sys_user = new SYS_USER();
            sys_user.AddDepartmentGridLookupEdit(this.glkDepartment, this.glkBranch.EditValue.ToString());
            this.glkDepartment.EditValue = item.DepartmentCode;
            sys_user.AddGroupGridLookupEdit(this.glkGroup, this.glkDepartment.EditValue.ToString());
            this.glkGroup.EditValue = item.GroupCode;
            this.glkEmployee.EditValue = item.EmployeeCode;
            if (!(MyRule.Get(MyLogin.RoleId, "bbiUsers") != "OK") && !MyRule.AllowEdit)
            {
                this.cboManagement.Enabled = false;
                this.glkBranch.Enabled = false;
                this.glkDepartment.Enabled = false;
                this.glkGroup.Enabled = false;
            }
        }

        public void SetEmployeeCode(string EmployeeCode)
        {
            this.glkEmployee.EditValue = EmployeeCode;
        }

        protected override void txtID_EditValueChanged(object sender, EventArgs e)
        {
        }

        protected override void txtID_KeyDown(object sender, KeyEventArgs e)
        {
        }

        private void txtNAME_EditValueChanged(object sender, EventArgs e)
        {
            TextEdit control = (TextEdit)sender;
            if (base.m_Status != Actions.None)
            {
                if (base.m_Status == Actions.Add)
                {
                    base.txtID.Text = GridCalendarControlLib.RejectMarks(base.txtNAME.Text);
                }
                if (control.ErrorText != string.Empty)
                {
                    base.Err.SetError(control, string.Empty);
                }
            }
        }

        private void txtPassword_Click(object sender, EventArgs e)
        {
        }

        private void txtRepassword_Click(object sender, EventArgs e)
        {
        }

        protected override string uc_Change()
        {
            return string.Empty;
        }

        protected override string uc_Delete()
        {
            string str = string.Empty;
            SYS_USER item = new SYS_USER
            {
                UserID = base.txtID.Text
            };
            str = item.Delete();
            if (str == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            return str;
        }

        protected override string uc_Save()
        {
            if (MyRule.Get(MyLogin.RoleId, "bbiUsers") != "OK")
            {
                return "";
            }
            if (!MyRule.AllowAdd)
            {
                MyRule.Notify();
                return "";
            }
            if (this.cboManagement.SelectedIndex == 1)
            {
                if ((this.glkBranch.EditValue == null) || (this.glkBranch.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn chi nh\x00e1nh!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
            }
            else if (this.cboManagement.SelectedIndex == 2)
            {
                if ((this.glkBranch.EditValue == null) || (this.glkBranch.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn chi nh\x00e1nh!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
                if ((this.glkDepartment.EditValue == null) || (this.glkDepartment.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn ph\x00f2ng ban cho chi nh\x00e1nh!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
            }
            else if (this.cboManagement.SelectedIndex == 3)
            {
                if ((this.glkBranch.EditValue == null) || (this.glkBranch.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn chi nh\x00e1nh!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
                if ((this.glkDepartment.EditValue == null) || (this.glkDepartment.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn ph\x00f2ng ban cho chi nh\x00e1nh!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
                if ((this.glkGroup.EditValue == null) || (this.glkGroup.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn tổ nh\x00f3m cho ph\x00f2ng ban!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
            }
            if ((base.txtNAME.Text == "admin") && (this.cbxGroup.EditValue.ToString() == "employee"))
            {
                XtraMessageBox.Show("T\x00e0i khoản người d\x00f9ng n\x00e0y kh\x00f4ng thể gắn với nh\x00f3m t\x00e0i khoản nh\x00e2n vi\x00ean!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return "";
            }
            SYS_USER item = new SYS_USER();
            try
            {
                if (((this.glkEmployee.EditValue != null) || (this.glkEmployee.EditValue.ToString() != "")) && item.ExistEmployeeCode(this.glkEmployee.EditValue.ToString()))
                {
                    XtraMessageBox.Show("M\x00e3 nh\x00e2n vi\x00ean n\x00e0y đ\x00e3 được sử dụng cho người d\x00f9ng kh\x00e1c!\r\nVui l\x00f2ng chọn lại nh\x00e2n vi\x00ean kh\x00e1c cho người d\x00f9ng n\x00e0y", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
            }
            catch
            {
            }
            SYS_LOG.Insert("Quản L\x00fd Người D\x00f9ng", "Th\x00eam", base.txtID.Text);
            base.CreateWaitDialog();
            base.SetWaitDialogCaption("Đang lưu dữ liệu...");
            Cursor.Current = Cursors.WaitCursor;
            string str = string.Empty;
            item = new SYS_USER(item.NewID(), base.txtNAME.Text, this.txtPassword.Text, this.cbxGroup.EditValue.ToString(), this.txtMail.Text, this.txtDescription.Text, "", this.cboManagement.SelectedIndex, (this.glkBranch.EditValue != null) ? this.glkBranch.EditValue.ToString() : "", (this.glkDepartment.EditValue != null) ? this.glkDepartment.EditValue.ToString() : "", (this.glkGroup.EditValue != null) ? this.glkGroup.EditValue.ToString() : "", (this.glkEmployee.EditValue != null) ? this.glkEmployee.EditValue.ToString() : "", this.chxUse.Checked);
            str = item.Insert();
            if (str == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            else
            {
                XtraMessageBox.Show("Lỗi:\n\t" + str, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.DoHide();
                return "";
            }
            Cursor.Current = Cursors.Default;
            this.DoHide();
            return str;
        }

        protected override string uc_Update()
        {
            if (MyRule.Get(MyLogin.RoleId, "bbiUsers") != "OK")
            {
                return "";
            }
            if (!MyRule.AllowEdit)
            {
                MyRule.Notify();
                return "";
            }
            if (this.cboManagement.SelectedIndex == 1)
            {
                if ((this.glkBranch.EditValue == null) || (this.glkBranch.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn chi nh\x00e1nh!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
            }
            else if (this.cboManagement.SelectedIndex == 2)
            {
                if ((this.glkBranch.EditValue == null) || (this.glkBranch.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn chi nh\x00e1nh!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
                if ((this.glkDepartment.EditValue == null) || (this.glkDepartment.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn ph\x00f2ng ban cho chi nh\x00e1nh!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
            }
            else if (this.cboManagement.SelectedIndex == 3)
            {
                if ((this.glkBranch.EditValue == null) || (this.glkBranch.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn chi nh\x00e1nh!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
                if ((this.glkDepartment.EditValue == null) || (this.glkDepartment.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn ph\x00f2ng ban cho chi nh\x00e1nh!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
                if ((this.glkGroup.EditValue == null) || (this.glkGroup.Text == ""))
                {
                    XtraMessageBox.Show("Vui l\x00f2ng chọn tổ nh\x00f3m cho ph\x00f2ng ban!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
            }
            if ((base.txtNAME.Text == "admin") && (this.cbxGroup.EditValue.ToString() == "employee"))
            {
                XtraMessageBox.Show("T\x00e0i khoản người d\x00f9ng n\x00e0y kh\x00f4ng thể gắn với nh\x00f3m t\x00e0i khoản nh\x00e2n vi\x00ean!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return "";
            }
            SYS_USER item = new SYS_USER();
            try
            {
                if (((this.glkEmployee.EditValue != null) || (this.glkEmployee.EditValue.ToString() != "")) && item.ExistEmployeeCode(this.glkEmployee.EditValue.ToString(), base.txtNAME.Text))
                {
                    XtraMessageBox.Show("M\x00e3 nh\x00e2n vi\x00ean n\x00e0y đ\x00e3 được sử dụng cho người d\x00f9ng kh\x00e1c!\r\nVui l\x00f2ng chọn lại nh\x00e2n vi\x00ean kh\x00e1c cho người d\x00f9ng n\x00e0y", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return "";
                }
            }
            catch
            {
            }
            SYS_LOG.Insert("Quản L\x00fd Người D\x00f9ng", "Cập Nhật", base.txtID.Text);
            base.CreateWaitDialog();
            base.SetWaitDialogCaption("Đang cập nhật dữ liệu...");
            string str = string.Empty;
            item = new SYS_USER(base.txtID.Text, base.txtNAME.Text, this.txtPassword.Text, this.cbxGroup.EditValue.ToString(), this.txtMail.Text, this.txtDescription.Text, "", this.cboManagement.SelectedIndex, (this.glkBranch.EditValue != null) ? this.glkBranch.EditValue.ToString() : "", (this.glkDepartment.EditValue != null) ? this.glkDepartment.EditValue.ToString() : "", (this.glkGroup.EditValue != null) ? this.glkGroup.EditValue.ToString() : "", (this.glkEmployee.EditValue != null) ? this.glkEmployee.EditValue.ToString() : "", this.chxUse.Checked);
            if (this.txtPassword.Text == "<Ẩn>")
            {
                str = item.UpdateNopass();
            }
            else
            {
                str = item.Update();
            }
            if (str == "OK")
            {
                this.RaiseSuccessEventHander(item);
                if (MyLogin.Account == item.UserName)
                {
                    MyLogin.Level = item.Management;
                    if (item.Management == 0)
                    {
                        MyLogin.Code = "";
                    }
                    else if (item.Management == 1)
                    {
                        MyLogin.Code = item.BranchCode;
                    }
                    else if (item.Management == 2)
                    {
                        MyLogin.Code = item.DepartmentCode;
                    }
                    else
                    {
                        MyLogin.Code = item.GroupCode;
                    }
                }
            }
            else
            {
                XtraMessageBox.Show("Lỗi:\n\t" + str, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.DoHide();
                return "";
            }
            this.DoHide();
            return str;
        }

        private void xfmGroupAdd_Added(object sender, SYS_GROUP Item)
        {
            this.cbxGroup.EditValue = Item.Group_ID;
        }

        public delegate void SuccessEventHander(object sender, SYS_USER Item);
    }
}